<%--
  Created by IntelliJ IDEA.
  User: 57998
  Date: 2020/10/20
  Time: 8:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="css/qiantai_login_copy.css" />
		<link rel="stylesheet" type="text/css" href="css/qiantai_login.css" />
		<script type="text/javascript" class="autoinsert" src="js/jquery-2.2.0.min.js"></script>
		<script type="text/javascript" class="autoinsert" src="js/layer.js"></script>
		<link rel="stylesheet" type="text/css" href="css/layer.css" />
		<script type="text/javascript" src="js/qiantai_login.js"></script>
	</head>
	<body>
		<section>
			<div id="loginbox" class="loginbox" style="margin-top: 8%;">
				<div class="part loginPart">
					<div id="login">
						<form class="loginform" method="post" action="#">
							<p class="input-item">
								<input class="input-control" id="username" type="text" placeholder="用户名" name="username" style="width: 100%;">
							</p>
							<p class="input-item">
								<input class="input-control" id="password" type="password" placeholder="密码" name="password" style="width: 100%;">
							</p>
							<p class="sign-tips"></p>
							<p class="input-submit">
								<input class="submit login-loader btn" type="button" value="登录" onclick="formClose()">
							</p>
							<p class="safe">
								<a class="lostpwd-loader left" href="#" onclick="show_zhaohui()">忘记密码？</a>
								<a class="signup-loader right" href="#" onclick="show_zhuce()">注册账号</a>
							</p>
						</form>
					</div>
					
					<script type="text/javascript">						
						function formClose() {
							if($("#username").val() == "" || $("#password").val() == ""){
								layer.msg('请将信息完整输入!', {
									time: 1500
								});
							}else{
								$.ajax({
									type: "POST",
									url: "${pageContext.request.contextPath}/qiantai_login",
									data: {
										username: $("#username").val(),
										password: $("#password").val()
									},
									dataType: "json",
									success: function(result) {
										console.log(result.code)
										if (result.code == "1") {
											// window.parent.location.reload();
											var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
											//layer.msg(index);
											parent.layer.close(index); //再执行关闭
											window.parent.location.reload();
											window.location.href="${pageContext.request.contextPath}/home";
										} else {
											layer.msg('用户名或密码错误!', {
												time: 1500
											});
										}
									},
									error: function() {
										//alert("請求失敗");
									}
								});
							}
						}
					</script>

					<!-- <script type="text/javascript">
						window.formClose = function() {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							//layer.msg(index);
							parent.layer.close(index); //再执行关闭   
						}
					</script> -->

					<div id="zhuce" hidden="hidden" style="margin-top: 3%;">
						<form id="regform" class="loginform" method="post" novalidate="novalidate" onSubmit="return false;" autocomplete="off">
							<p class="input-item">
								<input class="input-control" id="name" type="text" placeholder="用户名" name="name" style="width: 100%;">
							</p>
							<p class="input-item">
								<input class="input-control" id="email" type="email" placeholder="邮箱" name="email" style="width: 100%;">
							</p>
							<p class="input-item">
								<input class="input-control" id="new_password" type="password" placeholder="密码" name="new_password" style="width: 100%;">
							</p>
							<p class="sign-tips"></p>
							<p class="input-submit">
								<input class="submit register-loader btn" type="button" value="注册账号" onclick="new_user()">
							</p>
							<p class="safe" style="margin-bottom: 0px;">
								<a class="signin-loader" href="#" onclick="show_login()">返回登录</a>
							</p>
						</form>
					</div>

					<script type="text/javascript">
						function new_user() {
							if($("#name").val() == "" || $("#email").val() == "" || $("#new_password").val() == ""){
								layer.msg('请将信息完整输入!', {
									time: 1500
								});
							}else{
								$.ajax({
									type: "POST",
									url: "${pageContext.request.contextPath}/adduserinfo",
									data: {
										name: $("#name").val(),
										email: $("#email").val(),
										password: $("#new_password").val()
									},
									dataType: "json",
									success: function(result) {
										if (result.code == "1") {
											// window.parent.location.reload();
											var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
											//layer.msg(index);
											parent.layer.close(index); //再执行关闭
											window.parent.location.reload();
										} else {
											layer.msg('注册失败，请重试!', {
												time: 1500
											});
										}
									},
									error: function() {
										//alert("請求失敗");
									}
								});
							}
						}
					</script>

					<div id="zhaohui" hidden="hidden" style="margin-top:3%;">
						<form id="passform" class="loginform" method="post" novalidate="novalidate" onSubmit="return false;">
							<p class="input-item">
								<input class="input-control" id="passname" type="text" placeholder="用户名/电子邮箱" name="passname" style="width: 100%;margin-bottom: 5%;">
							</p>
							<p class="sign-tips"></p>
							<p class="input-submit">
								<input class="submit pass-loader btn" type="button" value="找回密码" onclick="get_password()">
							</p>
							<p class="safe">
								<a class="signin-loader" href="#" onclick="show_login()">返回登录</a>
							</p>
						</form>
					</div>

					<script type="text/javascript">
						function get_password() {
							if($("#passname").val() == ""){
								layer.msg('请将信息完整输入!', {
									time: 1500
								});
							}else{
								$.ajax({
									type: "POST",
									url: "#",
									data: {
										user_method: "get_password",
										passname: $("#passname").val()
									},
									dataType: "json",
									success: function(result) {
										if (result.code == "1") {
											layer.msg('密码已发送至相应邮箱，请注意查收', {
												time: 1500
											});
										} else if (result.code == "2") {
											layer.msg('请输入正确的邮箱', {
												time: 1500
											});
										} else {
											layer.msg('系统繁忙，请重试!', {
												time: 1500
											});
										}
									},
									error: function() {
										//alert("請求失敗");
									}
								});
							}
						}
					</script>

				</div>
			</div>
		</section>
	</body>
</html>

